import DefaultTheme from 'vitepress/theme';
import './style.css';

import 'viewerjs/dist/viewer.min.css';
import imageViewer from 'vitepress-plugin-image-viewer';
import vImageViewer from 'vitepress-plugin-image-viewer/lib/vImageViewer.vue';
import { useRoute } from 'vitepress';
export default {
  ...DefaultTheme,
  enhanceApp(ctx) {
    DefaultTheme.enhanceApp(ctx);
    // 注册全局组件（可选）
    ctx.app.component('vImageViewer', vImageViewer);
},
  setup() {
    const route = useRoute();
    imageViewer(route);
    const onMounted = () => {
      const sidebarGroups = document.querySelectorAll('.vp-sidebar-group');
      sidebarGroups.forEach((group) => {
        const title = group.querySelector('.vp-sidebar-item');
        title.addEventListener('click', () => {
          const sidebar = document.querySelector('.vp-sidebar');
          sidebar.classList.toggle('collapsed');
        });
      });
    };

    return {
      onMounted,
    };
  },
};
